﻿// SLTool.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <stdio.h>

#include <string>
#include <mutex>
#include "SLT_tool_pub.h"
#include "SL_asynFramePub.h"

class sessionTest : public SLF_SessionBase
{
public:
	~sessionTest() {
		printf("del sessionTest:\n");
	}
	virtual void OnStart() 
	{
		m_timer.start();
		printf("onstart:%s,sid:%u\n", m_name.c_str(), getSessID());
		setTimer(1, 1000, false);
		setTimer(2, 3000, false);
	};
	virtual void OnStop() 
	{
		printf("onstop:%s,sid:%u\n", m_name.c_str(), getSessID());
	};
	virtual void OnMsgArrive(SLF_senderPtr& _sender, uint32_t srcSid, int msgid, SLF_sendMemBasePtr& _data)
	{
		printf("recv msg:localID:%d,src:%d,msgid:%d\n",getSessID(), srcSid,msgid);
	}
	virtual void OnTimer(uint32_t timerID, int _intervalMs, bool periodic)
	{
		printf("OnTimer:%s,sid:%u,timer:%d,_intervalMs:%d\n", m_name.c_str(), getSessID(), timerID, _intervalMs);
		if (timerID == 6) {
			SLF_delSession(getSessID());
		}
		m_timer.start();
		if (timerID > 1) {
			timerID++;
			setTimer(timerID, 3000, false);
		}
		
	}

	SLT_elapseTimer  m_timer;
	std::string m_name;
};

int tool_asynframe_test_main()
{
	SLT_logInit();
    SLF_init(3);
    SLF_start();


	sessionTest* psession1 = new sessionTest();
	SLF_SessionBasePtr psession1Ptr(psession1);
	psession1->m_name = "sessino1";
	SLF_addSession(psession1Ptr);

	sessionTest* psession2 = new sessionTest();
	SLF_SessionBasePtr psession2Ptr(psession2);
	psession2->m_name = "sessino2";
	SLF_addSession(psession2Ptr);


	SLF_postMsg(psession2->getSessID(), 1, 0, SLF_sendMemBasePtr());

	getchar();
    return 0;
}

